package com.maple.admin.misc.menu.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.maple.admin.misc.menu.dao.IMenuDAO;
import com.maple.admin.misc.menu.dto.MenuDTO;
import com.maple.admin.misc.menu.service.IMenuService;
import com.maple.admin.misc.menu.util.MenuHelper;
import com.maple.admin.misc.paging.dto.PagingParamsDTO;

@Service
public class IMenuServiceImpl implements IMenuService {
	@Autowired
	IMenuDAO meunDAO;

	@Override
	public List<Object> queryAllMenus() {
		// TODO Auto-generated method stub
		List<Object> resultList = new ArrayList<Object>();
		List<MenuDTO> tmpList = meunDAO.queryAllMenus();
		resultList = MenuHelper.generateMenu(tmpList);
		return resultList;
	}

	@Override
	public List<MenuDTO> queryPaginatedMenus(PagingParamsDTO dto) {
		// TODO Auto-generated method stub
		Integer p = dto.getPage();
		// fix records index
		if(p <= 1){
			dto.setPage(0);
		}
		return meunDAO.queryPaginatedMenus(dto);
	}
	
}
